<div class="alert">
<?php
require_once('includes/user_manage.php');

$user->isAdmin or exit("Área reservada a administradores");

$my_item=new admin_item();
$my_item->id=$_GET["item_id"];
$my_item->set_from_array($_POST);
$updated=$my_item->db_update();
if ($updated==true) {
	$my_item->db_load();
	$serItem=json_encode($my_item);
?>
	Producto actualizado.
	<form id="myEditForm"><input type="hidden" value='<?php print htmlentities($serItem); ?>' name="serItem"></form>
<?php
}
else {
?>
	Ocurrió un error.
<?php
}
?>
</div>

<script type="text/javascript">
var categoryId=<?php print $my_item->category_id; ?>;
var itemId=<?php print $_GET["item_id"]; ?>;
	var catalogPointer=myCatalog;
	catalogPointer=catalogPointer.moveToChildren("categoryId", categoryId);
	if (!catalogPointer.myCategory.id) {
		catalogPointer=catalogPointer.moveToChildren("selected");
		catalogPointer=catalogPointer.moveToChildren("categoryId", categoryId);
	}

var serItem=document.getElementById("myEditForm").serItem.value;
for (var i in catalogPointer.items) {
	if (catalogPointer.items[i].id==itemId) {
		var myItem=catalogPointer.items[i];
		break;
	}
}
myItem.setFromArray(JSON.parse(serItem));
myItem.mySetView(catalogPointer.myItemView.cloneNode(true));
	
window.setTimeout(removeAlert,2000,document.getElementById('editWindow'));
function removeAlert(alert) {
	alert.parentNode.removeChild(alert);
}
</script>